package sample.reflects;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class HelloInvoke {

	public static void main(String[]args){
		Class<?> demo=null;
		try {
			demo=Class.forName("sample.reflects.Person3");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		
		try {
			Method methods=demo.getMethod("sayChina");
			try {
				methods.invoke(demo.newInstance());
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				e.printStackTrace();
			} catch (InstantiationException e) {
				e.printStackTrace();
			}
			methods=demo.getMethod("sayHello", String.class,int.class);
			try {
				//...
				methods.invoke(demo.newInstance(),"anqing",20);
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				e.printStackTrace();
			} catch (InstantiationException e) {
				e.printStackTrace();
			}
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		}
	}
}
